package com.zbkj.crmeb.store.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.common.CommonPage;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import com.zbkj.crmeb.store.dao.StoreSeasonDao;
import com.zbkj.crmeb.store.model.StoreSeason;
import com.zbkj.crmeb.store.request.StoreSeasonRequest;
import com.zbkj.crmeb.store.service.StoreSeasonService;

@Service
public class StoreSeasonServiceImpl extends ServiceImpl<StoreSeasonDao, StoreSeason> implements StoreSeasonService {
    @Resource
    private StoreSeasonDao storeSeasonDao;

    @Override
    public PageInfo<StoreSeason> pageEntity(StoreSeasonRequest request) {
        Page<Object> page = PageHelper.startPage(request.getPageNow(), request.getPageSize());
        List<StoreSeason> storeSeasons = this.list(Wrappers.<StoreSeason>lambdaQuery()
        		.eq(StringUtil.isNotEmpty(request.getName()), StoreSeason :: getName, request.getName())
        		);
        
        return CommonPage.copyPageInfo(page, storeSeasons);
    }

    @Override
    public StoreSeason getEntityById(Integer id) {
        return this.getOne(Wrappers.<StoreSeason>lambdaQuery().eq(StoreSeason::getId, id));
    }

    @Override
    public Integer saveEntity(StoreSeason request) {
        request.setCreateTime(new Date());
        request.setUpdateTime(new Date());
        
        return storeSeasonDao.insert(request);
    }
    
    @Override
    public Integer updateEntity(StoreSeason request) {
    	request.setUpdateTime(new Date());
        
    	return storeSeasonDao.updateById(request);
    }

    @Override
    public List<StoreSeason> selectEntityList() {
        List<StoreSeason> storeSeasons = this.list(Wrappers.<StoreSeason>lambdaQuery());
        
        return storeSeasons;
    }

}
